<template>
	<view>
		<liu-pageTab-bar index='1' :activeColor="'#333'"></liu-pageTab-bar>
		<view class='newsList'>

			<view class='nav' v-if="navList.length > 0">
				<block v-for="(item,index) in navList" :key="index">
					<view class='item' :class='active==item.id?"on":""' @click='tabSelect(item.id, index)'>
						<view>{{item.name}}</view>
						<!-- <view class='line bg-color' v-if="active==item.id"></view> -->
					</view>
				</block>
				<!-- <scroll-view class="scroll-view_x" scroll-x scroll-with-animation :scroll-left="scrollLeft"
					style="width:auto;overflow:hidden;">
					<block v-for="(item,index) in navList" :key="index">
						<view class='item borRadius14' :class='active==item.id?"on":""'
							@click='tabSelect(item.id, index)'>
							<view>{{item.name}}</view>
							<view class='line bg-color' v-if="active==item.id"></view>
						</view>
					</block>
				</scroll-view> -->
			</view>
			<view class='list'>
				<block v-for="(item,index) in articleList" :key="index">
					<navigator @click="goPage(item)" hover-class='none'
						class='item acea-row row-between-wrapper1'>
						<view class='pictrue'>
							<!-- <image src="../../static/logo.png" mode=""></image> -->
							<image :src='item.imageInput'></image>
						</view>
						<view class='text acea-row row-column-between'>
							<view>
								<view class='name line1'>{{item.title}}</view>
								<view>{{item.createTime}}</view>
							</view>
							<view class="dis" style="align-items: center;margin-right: 10rpx;">
								<image style="width: 40rpx;height: 40rpx;" src="@/static/com/icon_look.png" mode="">
								</image>
								已阅人数{{item.visit||0}}
							</view>

						</view>

					</navigator>
				</block>
			</view>
		</view>
		<view class="ding">

		</view>
		<view class='noCommodity' v-if="articleList.length == 0 && (page != 1 || active== 0)">
			<view class='pictrue' style="text-align: center;">
				<image src="https://gfry.oss-cn-hangzhou.aliyuncs.com/crmebimage/public/content/2024/03/07/icon_nodata.png" mode=""></image>
				暂无数据
				<!-- <image src='../../static/images/noNews.png'></image> -->
			</view>
		</view>
		<home></home>
	</view>
</template>

<script>
	import {
		getArticleCategoryList,
		getArticleList,
		getArticleHotList,
		getArticleBannerList
	} from '@/api/api.js';
	import home from '@/components/home';
	export default {
		components: {
			home
		},
		data() {
			return {

				imgUrls: [],
				articleList: [],
				indicatorDots: false,
				circular: true,
				autoplay: true,
				interval: 3000,
				duration: 500,
				navList: [],
				active: 1,
				page: 1,
				limit: 8,
				status: false,
				scrollLeft: 0
			};
		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			this.getArticleHot();
			this.getArticleBanner();
			this.getArticleCate();
			this.status = false;
			this.page = 1;
			this.articleList = [];
			this.getCidArticle();
		},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {
			this.getCidArticle();
		},
		methods: {
			goPage(item){
				if(item.type==2){
					uni.navigateTo({
						url: '/pagesA/web/webview?url=' + item.url
					})
				
				}else if(item.type==1){
					uni.navigateTo({
						url:"/pages/news_details/index?id="+item.id
					})
				}
				
			},
			getArticleHot: function() {
				let that = this;
				getArticleHotList().then(res => {
					that.$set(that, 'articleList', res.data.list);
				});
			},
			getArticleBanner: function() {
				let that = this;
				getArticleBannerList().then(res => {
					that.imgUrls = res.data.list;
				});
			},
			getCidArticle: function() {
				let that = this;
				if (that.active == 0) return;
				let limit = that.limit;
				let page = that.page;
				let articleList = that.articleList;
				if (that.status) return;
				getArticleList(that.active, {
					page: page,
					limit: limit
				}).then(res => {
					let articleListNew = [];
					let len = res.data.list.length;
					articleListNew = articleList.concat(res.data.list);
					that.page++;
					that.$set(that, 'articleList', articleListNew);
					that.status = limit > len;
					that.page = that.page;
				});
			},
			getArticleCate: function() {
				let that = this;
				getArticleCategoryList().then(res => {
					let list = res.data.list;
					// console.log(list, 'wishisha ')
					// list.unshift({
					// 	id: 0,
					// 	name: '热门'
					// });
					this.active = list[0].id
					that.$set(that, 'navList', list);
				});
			},
			tabSelect(active, e) {
				this.active = active;
				this.scrollLeft = e * 60;
				// this.scrollLeft = (active - 1) * 50;
				if (this.active == 0) this.getArticleHot();
				else {
					this.$set(this, 'articleList', []);
					this.page = 1;
					this.status = false;
					this.getCidArticle();
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #fff !important;
	}

	.swiper {
		width: 100%;
		justify-content: space-between;

		.swiper-msg {
			width: 30%;
			border-radius: 100rpx;
			background: red;
		}
	}


	.newsList .nav {
		padding: 0 24rpx;
		width: 100%;
		white-space: nowrap;
		box-sizing: border-box;
		margin-top: 43rpx;
		display: flex;
		justify-content: space-around;
	}

	.newsList .nav .item {
		padding: 12rpx 0;
		font-size: 32rpx;
		text-align: center;
		/* line-height: 18px; */
		border: 1px solid;
		align-items: center;
		color: #999;
		width: 200rpx;
		border-radius: 100rpx;

	}

	.newsList .nav .item.on {
		color: #fff;
		border: none !important;
		background: $maincolor;
	}

	.newsList .nav .item~.item {
		margin-left: 46rpx;
	}

	.newsList .nav .item .line {
		width: 24rpx;
		height: 4rpx;
		border-radius: 2rpx;
		margin: 10rpx auto 0 auto;
	}

	.newsList .list .item {
		margin: 0 24rpx;
		border-bottom: 1rpx solid #f0f0f0;
		padding: 35rpx 0;
	}

	.newsList .list .item .pictrue {
		width: 190rpx;
		height: 190rpx;
	}

	.row-between-wrapper1 {
		-o-box-align: center;
		align-items: center;
		-o-box-pack: justify;


	}

	.newsList .list .item .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 14rpx;
	}

	.newsList .list .item .text {
		width: 420rpx;
		height: 156rpx;
		font-size: 24rpx;
		color: #999;
		margin-left: 20rpx;
	}

	.newsList .list .item .text .name {
		font-size: 30rpx;
		width: 500rpx;
		color: #282828;
	}

	.newsList .list .item .picList .pictrue {
		width: 335rpx;
		height: 210rpx;
		margin-top: 30rpx;
	}

	.newsList .list .item .picList.on .pictrue {
		width: 217rpx;
		height: 136rpx;
	}

	.newsList .list .item .picList .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 6rpx;
	}

	.newsList .list .item .time {
		text-align: right;
		font-size: 24rpx;
		color: #999;
		margin-top: 22rpx;
	}
</style>